const TokenKey = 'Admin-Token';

// 存储授权参数的key
const OAUTH_PARAMS_KEY = 'server_oauth_params';

const tokenStorage = useStorage<null | string>(TokenKey, null);

export const getToken = () => tokenStorage.value;

export const setToken = (access_token: string) => (tokenStorage.value = access_token);

export const removeToken = () => (tokenStorage.value = null);

// 新增：存储OAuth2授权参数到localStorage
export const setOAuthParams = (params: Record<string, any>) => {
  localStorage.setItem(OAUTH_PARAMS_KEY, JSON.stringify(params));
};

// 新增：获取存储的OAuth2授权参数
export const getOAuthParams = () => {
  const params = localStorage.getItem(OAUTH_PARAMS_KEY);
  return params ? JSON.parse(params) : null;
};

// 新增：清除OAuth2授权参数
export const clearOAuthParams = () => {
  localStorage.removeItem(OAUTH_PARAMS_KEY);
};
